<?php
/**
 * Hoffman Framework
 *
 * LICENSE
 *
 * This source file is subject to the GNU LGPL 2.1 license that is bundled
 * with this package in the file license.txt.
 * It is also available through the world-wide-web at this URL:
 * http://creativecommons.org/licenses/LGPL/2.1
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to annop@thaicyberpoint.com so we can send you a copy immediately.
 *
 * @package    Hoffman
 * @author     Ford AntiTrust
 * @copyright  Copyright (c) 2008 Ford AntiTrust (http://www.thaicyberpoint.com/ford/blog)
 * @since      Version Rv 0.2
 * @license    http://creativecommons.org/licenses/LGPL/2.1
 *             GNU LGPL 2.1
 * @filesource
 */

if (!defined('INDEX'))
    die('No direct script access allowed.');

/**
 * @see Zend_Register
 */
require_once 'Zend/Registry.php';
/**
 * @see Hmf_Locale
 */
require_once 'Hmf/Locale.php';
/**
 * @see Hmf_Translate
 */
require_once 'Hmf/Translate.php';
/**
 * @see Hmf_Httppage
 */
require_once 'Hmf/Httppage.php';

/**
 * Default Hmf Helpers Fucntions
 *
 * @package     Hmf Helpers Fucntions
 * @author      Ford AntiTrust
 * @version     SVN: $Id: Hmf.php 137 3095-01-19 10:03:59Z annop.s@gmail.com $
 * @link        http://www.thaicyberpoint.com/ford/blog/hmf
 *
 */

/**
 * @see Hmf_Acl#isAllowed()
 */

function isAllowed($controller, $action, $role = null) {

    if (is_null($role))
        $role = Zend_Registry::get('app_authen')->getRole();

    return Zend_Registry::get('app_acl')->isAllowed($role, $controller, $action);
}

/**
 * @see Hmf_Authen#getRole()
 */

function getAuthenRole() {

    return Zend_Registry::get('app_authen')->getRole();
}

/**
 * @see Hmf_Authen#getInfo()
 */

function getAuthenInfo() {

    return Zend_Registry::get('app_authen')->getInfo();
}

/**
 * @see Hmf_Authen#setRole()
 */

function setAuthenRole($role) {

    Zend_Registry::get('app_authen')->setRole($role);
}

/**
 * @see Hmf_Authen#setInfo()
 */

function setAuthenInfo($data) {

    Zend_Registry::get('app_authen')->setInfo($data);
}

/**
 * @see Hmf_Authen#setInfo()
 */

function isAuthenRole($role) {

    return Zend_Registry::get('app_authen')->isRole($role);
}

/**
 * @see Hmf_Authen#clear()
 */

function clearAuthen() {

    return Zend_Registry::get('app_authen')->clear();
}

/**
 * @see Hmf_Routing#getCurrentUrlAction()
 */
function currentUrlAction() {

    return Zend_Registry::get('routing_url')->getCurrentUrlAction();
}

/**
 * @see Hmf_Httppage#isCurrentUrlAction()
 */
function isCurrentUrlAction() {

    $args = func_get_args();
    return call_user_func_array(array('Hmf_Httppage', 'isCurrentUrlAction'), $args);
}

/**
 * @see Hmf_Httppage#redirect()
 */
function go() {

    $args = func_get_args();
    return call_user_func_array(array('Hmf_Httppage', 'redirect'), $args);
}

/**
 * @see Hmf_Httppage#redirectToHttp()
 */
function goHttp() {

    $args = func_get_args();
    return call_user_func_array(array('Hmf_Httppage', 'redirectToHttp'), $args);
}

/**
 * @see Hmf_Httppage#link()
 */
function l() {

    $args = func_get_args();
    return call_user_func_array(array('Hmf_Httppage', 'link'), $args);
}

/**
 * @see Hmf_Httppage#url()
 */
function u() {

    $args = func_get_args();
    return call_user_func_array(array('Hmf_Httppage', 'url'), $args);
}

/**
 * @see Hmf_Httppage#baseUrl()
 */
function baseUrl() {

    $args = func_get_args();
    return call_user_func_array(array('Hmf_Httppage', 'baseUrl'), $args);
}

/**
 * @see Hmf_Translate#_t()
 */
function t() {

    $args = func_get_args();
    return call_user_func_array(array('Hmf_Translate', '_t'), $args);
}

/**
 * @see Hmf_Translate#_e()
 */
function e() {

    $args = func_get_args();
    return call_user_func_array(array('Hmf_Translate', '_e'), $args);
}

/**
 * @see Hmf_Translate#_s()
 */
function s() {

    $args = func_get_args();
    return call_user_func_array(array('Hmf_Translate', '_s'), $args);
}

/**
 * @see Hmf_Translate#_p()
 */
function p() {

    $args = func_get_args();
    return call_user_func_array(array('Hmf_Translate', '_p'), $args);
}

/**
 * @see CI_Hmf_Translate#_v()
 */
function v() {
    $args = func_get_args();
    return call_user_func_array(array('CI_Hmf_Translate', '_v'), $args);
}

/**
 * @see Hmf_Config#getConfig()
 */
function getConfig($key) {

    return Hmf_Config::getConfig($key);
}

function isEnvironmentProduction() {

    return (strcmp(ENVIRONMENT, 'production') == 0 ? true : false);
}

function isEnvironmentDevelopment() {

    return (strcmp(ENVIRONMENT, 'development') == 0 ? true : false);
}

function isEnvironmentTester() {

    return (strcmp(ENVIRONMENT, 'tester') == 0 ? true : false);
}

/**
 * @see Hmf_Instance#getModel()
 */

function getInstanceModel($name) {

    return Hmf_Instance::getModel($name);
}

/**
 * @see Hmf_Instance#getComponent()
 */

function getInstanceComponent($name, array $args = array()) {

    return Hmf_Instance::getComponent($name, $args);
}

/**
 * Clean urls through readable slugs
 *
 * @param $url
 * @return string
 */
function urlSlug($string, $space = "-") {

    if (function_exists('iconv')) {
        $string = @iconv('UTF-8', 'ASCII//TRANSLIT//', $string);
    }

    $string = preg_replace("/[^a-zA-Z0-9 -]/", "", $string);
    $string = strtolower($string);
    $string = str_replace(" ", $space, $string);

    return $string;
}